package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.service.IClassManagementService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Officialstudent;
import com.ruoyi.system.service.IOfficialstudentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 正式学生Controller
 *
 * @author ruoyi
 * @date 2021-11-09
 */
@Controller
@RequestMapping("/system/Officialstudent")
public class OfficialstudentController extends BaseController
{
    private String prefix = "system/Officialstudent";
    @Autowired
    private IClassManagementService service;
    @Resource
    private IOfficialstudentService officialstudentService;

    @RequiresPermissions("system:Officialstudent:view")
    @GetMapping()
    public String Officialstudent()
    {
        return prefix + "/Officialstudent";
    }

    /**
     * 查询正式学生列表
     */
    @RequiresPermissions("system:Officialstudent:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Officialstudent officialstudent)
    {
        startPage();
        List<Officialstudent> list = officialstudentService.selectOfficialstudentList(officialstudent);
        return getDataTable(list);
    }

    /**
     * 导出正式学生列表
     */
    @RequiresPermissions("system:Officialstudent:export")
    @Log(title = "正式学生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Officialstudent officialstudent)
    {
        List<Officialstudent> list = officialstudentService.selectOfficialstudentList(officialstudent);
        ExcelUtil<Officialstudent> util = new ExcelUtil<Officialstudent>(Officialstudent.class);
        return util.exportExcel(list, "正式学生数据");
    }

    /**
     * 新增正式学生
     */
    @GetMapping("/add")
    public String add(ModelMap map)
    {

        System.out.println();
        map.addAttribute("class",service.classs());
        return prefix + "/add";
    }

    /**
     * 新增保存正式学生
     */
    @RequiresPermissions("system:Officialstudent:add")
    @Log(title = "正式学生", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Officialstudent officialstudent)
    {
        return toAjax(officialstudentService.insertOfficialstudent(officialstudent));
    }

    /**
     * 修改正式学生
     */
    @GetMapping("/edit/{regularId}")
    public String edit(@PathVariable("regularId") String regularId, ModelMap mmap)
    {
        mmap.addAttribute("class",service.classs());
        Officialstudent officialstudent = officialstudentService.selectOfficialstudentByRegularId(regularId);
        mmap.put("officialstudent", officialstudent);
        return prefix + "/edit";
    }

    /**
     * 修改保存正式学生
     */
    @RequiresPermissions("system:Officialstudent:edit")
    @Log(title = "正式学生", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Officialstudent officialstudent)
    {
        return toAjax(officialstudentService.updateOfficialstudent(officialstudent));
    }

    /**
     * 删除正式学生
     */
    @RequiresPermissions("system:Officialstudent:remove")
    @Log(title = "正式学生", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(officialstudentService.deleteOfficialstudentByRegularIds(ids));
    }
}
